package com.znf4.controller.user;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.znf4.base.BaseReturnModel;
import com.znf4.id.IdGenerator;
import com.znf4.user.account.entity.UserAccount;
import com.znf4.user.account.server.UserAccountServer;

/**
 * 账户信息 
 */
@RestController
@RequestMapping("/user/account")
public class UserAccountController {
	
	@Autowired
	private UserAccountServer userAccountServer ;
	
	@Autowired
	private IdGenerator idGenerator ;
	
	

	/**
	 * 函数功能说明 ： 添加农作物商品规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/add", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> add(UserAccount userAccount , Model model) {
		
		userAccount.setId(idGenerator.getAccountInAndOutId());
		userAccountServer.addUserAccount(userAccount);
		return BaseReturnModel.getMapModel("success", "操作完成" , "");
	}

	
	
	/**
	 * 函数功能说明 ： 修改农作物商品规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/update", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> update(UserAccount userAccount , Model model) {
		
		userAccountServer.updateUserAccount(userAccount);
		return BaseReturnModel.getMapModel("success", "操作完成" , "");
	}

	/**
	 * 函数功能说明 ： 删除农作物商品规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delOne", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> delOne(UserAccount userAccount , Model model) {
		
		userAccountServer.delOneUserAccount(userAccount); 
		return BaseReturnModel.getMapModel("success", "操作完成" , "");
	}

	/**
	 * 函数功能说明 ： 删除多条农作物商品规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delAll", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> delAll(String[]  ids , Model model) {
		
		List<UserAccount> list = new ArrayList<>() ;
		for(int i=0 ; i < ids.length ; i ++ ){
			UserAccount userAccount = new UserAccount() ;
			userAccount.setId(ids[i]);
			list.add(userAccount) ;
		}
		userAccountServer.delAllUserAccount(list);
		return BaseReturnModel.getMapModel("success", "操作完成" , "");
	}
	

	/**
	 * 函数功能说明 ： 获取农作物所有的规格
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/queryAll", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> queryAll(UserAccount userAccount , Model model) {
		
		List<UserAccount> list = userAccountServer.queryAll(userAccount);
		return BaseReturnModel.getMapModel("success", list , "");
	}
	
	

}
